/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate.dao;

import hibernate.entity.EntityTypes;
import java.util.List;
import util.HibernateUtil;

/**
 *
 * @author NDH1
 */
public class EntityTypeDAO extends AbstractDAO {

    /**
     * @return List<EntityTypes>
     * @see a whole list table of courses
     */
    public List<EntityTypes> readAll() {
        session = HibernateUtil.getSessionFactory().openSession();
        query = session.createQuery("from EntityTypes");
        return query.list();
    }

    /**
     * @param name a name for find and get the appropriate entity type.
     * @return EntityTypes
     * @see EntityTypes
     */
    public EntityTypes readByName(String name) {
        try {
            session = HibernateUtil.getSessionFactory().openSession();
            query = session.createQuery("from EntityTypes where name = :name ");
            query.setParameter("name", name);
            return (EntityTypes) query.list().get(0);
        } catch (Exception e) {
        }
        return null;
    }

    /**
     * @param id an id for find and get the appropriate entity type.
     * @return EntityTypes
     * @see EntityTypes
     */
    public EntityTypes readByID(int id) {
        session = HibernateUtil.getSessionFactory().openSession();
        try {
            query = session.createQuery("from EntityTypes  where typeId = :id");
            query.setParameter("id", id);
            return (EntityTypes) query.list().get(0);
        } catch (Exception e) {
            return null;
        }
    }
}
